MySQL version: 5.6.24
I. scene One: Replace into operation on a table without a primary key or a unique key
CREATE TABLE ' Student ' (' SID ' varchar (6) Not NULL,' Name ' varchar ' not NULL DEFAULT ',' class ' varchar not NULL DEFAULT ',' Score '
Analysis of MySQL replace into statements (1)
This article mainly introduces the MySQL replace into Statement Analysis (1). This article describes the principle, usage, use cases, and examples of replace into. For more information, see
1.
This article mainly introduces the MySQL replace into statement (a), this article explains the principle of replace into, the use of the method and the use of the scene and the use of examples, the need for friends can refer to the
An introduction
MySQL replace into Statement Analysis (1), mysqlreplace
1. Introduction
I often encounter development consultation replace into application scenarios and precautions when supporting my business. Here is a summary. The functional principle,
Create a new test table, three fields, Id,title,uid, ID is the self-increment primary key, UID is the unique index;Insert two piece of data insert into test (TITLE,UID) values ( ' 123465" 1001 "insert into test (TITLE,UID) values ( ' 123465" 1002
An introduction
In the author supports the business process, often encounters the development consultation replace into the use scene as well as the attention matter, here makes a summary. Make a description from the functional principle,
Create a new test table, three fields, Id,title,uid, ID is the self-increment primary key, UID is the unique index;Insert two piece of dataINSERT INTO test (TITLE,UID) VALUES (' 123465 ', ' 1001 ') and insert into test (TITLE,UID) VALUES (' 123465
When you insert data into a table, you often encounter situations like this:
1, first judge whether the data exists;2, if it does not exist, then insert;3, if present, then update.You can write this in SQL Server:
Copy Code code as follows:
from:http://blog.xupeng.me/2013/10/11/mysql-replace-into-trap/MySQL has a lot of extensions for SQL, some of which are handy, but there are performance issues with some of them being misused, and there are some unintended side effects, like REPLACE
MySQL has a lot of extensions for SQL, some of which are handy, but there are performance issues with some of them being misused, and there are some unintended side effects, like REPLACE into.For example, there is a table:
12345678
This article mainly introduces the MySQL replace into the sentence analysis (ii), this article focuses on a number of special case analysis, the need for friends can refer to the
An introduction
The basic principle of replace into is introduced in
Analysis of MySQL replace into statements (2)
This article mainly introduces the MySQL replace into Statement Analysis (2). This article focuses on several special case studies. For more information, see
1. Introduction
The previous article
Today, when I was programming, I learned the use of replace into, which is really useful, is the enhanced version of INSERT INTO. When inserting data into a table, we often encounter situations such as: 1, first to determine whether the data exists,
MySQL replace into Statement Analysis (2), mysqlreplace
1. Introduction
The previous article introduced the basic principles of replace. This chapter uses an example to describe the potential data quality risks caused by replace into. When a table
MySQL "replace into", mysqlreplaceinto
MySQL has many extensions for SQL, some of which are very convenient to use, but some may have performance problems after misuse, and some unexpected side effects, such as REPLACE.
For example, there is a table:
Mysql replace into instance details
Mysql replace into instance details
Replace into is similar to insert. The difference is that replace into first tries to insert data into the table. Mysql replace into instance details
1. If this row of data
Error Code: 1062. Duplicate entry 'xxxxx' for key 'primary' (PRIMARY key conflict)In this way, we have to check whether the primary key exists. If it exists, it is updated. If it does not exist, it is inserted. Or write an SQL flow control statement
An introduction
The basic principle of replace into is introduced in the previous article. This chapter provides an example of the potential data quality risk associated with the replace into, and when a table involving a replace into operation
This can be done in SQL Server:
Copy Code code as follows:
If not exists (select 1 from t where id = 1)
INSERT into T (ID, Update_time) VALUES (1, GETDATE ())
Else
Update T Set update_time = GETDATE () Where id = 1
So
The Replace statement is generally similar to insert, but if there is a primary or a unique index in the table, if the inserted data is the same as the original primary key or unique, the original data is deleted, and then a new piece of data is
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.